﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FantasyDraft
{
    public partial class Form3 : Form
    {
        public string team1;
        public string team2;
        public string team3;
        public string team4;
        private int NumTeams;
        public bool isValid { get; set; }

        public Form3(int teams)
        {
            InitializeComponent();
            this.NumTeams = teams;
           

            switch (teams)
            {
                case 2: 
                    label4.Visible = false;
                    label5.Visible = false;
                    nameBox3.Visible = false;
                    nameBox4.Visible = false;
                    break;
                case 3:
                    label5.Visible = false;
                    nameBox4.Visible = false;
                    break;
                default:
                    break;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int mix;

            if (isValid)
            {
                Random randomTeam = new Random();
                mix = randomTeam.Next(1, this.NumTeams);

                switch (mix)
                {
                    case 1:
                        this.team1 = nameBox1.Text;
                        this.team2 = nameBox2.Text;
                        this.team3 = nameBox3.Text;
                        this.team4 = nameBox4.Text;
                        break;
                    case 2:
                        this.team1 = nameBox2.Text;
                        this.team2 = nameBox1.Text;
                        this.team3 = nameBox3.Text;
                        this.team4 = nameBox4.Text;
                        break;
                    case 3:
                        this.team1 = nameBox3.Text;
                        this.team2 = nameBox2.Text;
                        this.team3 = nameBox1.Text;
                        this.team4 = nameBox4.Text;
                        break;
                    case 4:
                        this.team1 = nameBox4.Text;
                        this.team2 = nameBox3.Text;
                        this.team3 = nameBox2.Text;
                        this.team4 = nameBox1.Text;
                        break;
                    default:
                        this.team1 = nameBox1.Text;
                        this.team2 = nameBox2.Text;
                        this.team3 = nameBox3.Text;
                        this.team4 = nameBox4.Text;
                        break;
                }

            }
            else
            { 
                isValid = true;
                return;

            }
        }
        private void nameBox1_Validating(object sender, CancelEventArgs e)
        {
            if (string.IsNullOrEmpty(nameBox1.Text))
            {

                e.Cancel = true;
                isValid = false;
                this.TeamNamesErrorProvider.SetError(nameBox1, "Team Name is required!");
                nameBox1.Focus();
            }
            else
            { 
                isValid = true;
                nameBox2.Focus(); 
            }
        }

        private void nameBox2_Validating(object sender, CancelEventArgs e)
        {
            if (string.IsNullOrEmpty(nameBox2.Text))
            {
                e.Cancel = true; 
                isValid = false;
                this.TeamNamesErrorProvider.SetError(nameBox2, "Team Name is required!");
                nameBox2.Focus();
            }
            else
            { 
                isValid = true; 
            }
        }

        private void nameBox1_Validated(object sender, EventArgs e)
        {
            this.TeamNamesErrorProvider.SetError(nameBox1, string.Empty);
        }

      
        private void nameBox2_Validated(object sender, EventArgs e)
        {
            this.TeamNamesErrorProvider.SetError(nameBox2, string.Empty);
        }
    
         
        
    }
}
